import os
from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chaohua.settings.dev")  # 设置项目的配置文件
app = Celery('chaohua')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

from celery.signals import after_setup_logger
import logging


# @after_setup_logger.connect
# def setup_loggers(logger, *args, **kwargs):
#     # 创建一个文件处理器
#     file_handler = logging.FileHandler('celery_dynamic.log')
#     file_handler.setLevel(logging.DEBUG)
#     file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
#
#     # 将文件处理器添加到 Celery 记录器中
#     logger.addHandler(file_handler)